package com.woniuxy.carrental.controller;

import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.Parking;
import com.woniuxy.carrental.entity.RentCarInfo;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author author
 * @create 2021-10-10 22:44
 */
@RestController
public class ParkingController {
   @Autowired
   ParkingService parkingService;

   @GetMapping("/getParking")
   public List<Parking> getParking(){
       List<Parking> parking = parkingService.getParking();
       return parking;
   }



    @PostMapping("/addParking")
    public String addParking(@RequestBody Parking parking){
        System.out.println(parking);
        parkingService.addParking(parking);
        return "添加成功";
    }


    @GetMapping("/getparkingBylist")
    public ResponseResult<PageBean<Parking>> getWarnRecord(Parking parking, int pageIndex, int pageSize){
        System.out.println("查询条件："+parking);
        System.out.println("pageSize："+pageSize);
        System.out.println("pageIndex："+pageIndex);

        int i = parkingService.selectParkingCountBylimit(parking);
        List<Parking> parkings = parkingService.selectAllParking(parking, pageIndex, pageSize);
        System.out.println("pakings"+parkings);
        PageBean<Parking> pageBean=new PageBean();
        pageBean.setBeanList(parkings);
        pageBean.setPageIndex(pageSize);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);

        return new ResponseResult<PageBean<Parking>>(pageBean,200,"ok");
    }





    @PutMapping("/updateparking")
    public String updateRenrCarIn(@RequestBody Parking parking){
        System.out.println(parking);
        parkingService.updateParking(parking);
        return "修改成功";
    }

    @DeleteMapping("/deleteparking/{parkid}")
    public String eletedRenrCarIn(@PathVariable ("parkid") int parkid){
        System.out.println(parkid);
        parkingService.delectParkingByid(parkid);
        return "删除成功";
    }


    @PutMapping ("/updateparkingparkid/{parkid}")
    public String updateparkingparkid(@PathVariable ("parkid") int parkid){
        System.out.println(parkid);
        parkingService.updateStareParking(parkid);
        return "修改成功";
    }




    @GetMapping("/getRentCarInfoByPid/{lonlat}")
    public List<RentCarInfo> getRentCarInfoByPid(@PathVariable ("lonlat") String lonlat){
        List<RentCarInfo> rentCarInfos = parkingService.selectRentCarInfoByPid(lonlat);
        return rentCarInfos;
    }





}
